﻿/*
 * ============ [ 废土 ] ============
 *
 * [ 维护者 ]  argoran@gmail.com
 * [  状态  ]  原型
 *
 * ============ [ 注释 ] ============
 *
 * 客户端程序入口
 *
 * ==================================
 */

using System;

using LastLandClient.Data;

using Up2Link.SegString;
using Up2Link.Util;

namespace LastLandClient.Core
{
    public class CLastLandClient
    {
        public static void Main(string[] _args)
        {                        
            CData.console = new CConsole();
            CData.command = new CCommand();
            CData.message = new CMessage();

            CData.clientOn = true;
            CData.console.SendOutput("欢迎使用", Console.ForegroundColor);
            CData.console.SendOutput("《废土 Last Land (开发代号)》", ConsoleColor.Cyan);
            CData.console.SendOutput("客户端程序");
            //CData.console.SendOutput("输入help阅读服务器使用说明");
            CData.console.Start();
            while (CData.clientOn)
            {
                String input = CData.console.ReceiveInput();
                if (input != null)
                {
                    String[] split = input.Split(CConst.DELIMITER_COMMAND);
                    if (split.Length >= 2)
                    {
                        CData.command.ExecuteCommand(split[0].ToLowerInvariant().Trim(), split[1].ToLowerInvariant().Trim());
                    }
                    else
                    {
                        CData.command.ExecuteCommand(split[0].ToLowerInvariant().Trim(), null);
                    }
                }
                if (CData.client != null && CData.client.isClientOn())
                {
                    CMessageSS msg = CData.client.Receive();
                    if (msg != null)
                    {
                        CData.message.ProcessMessage(msg);
                    }
                }
                if (CData.client != null && !CData.client.isClientOn())
                {
                    CData.client = null;
                    CData.console.SendOutput("");
                    CData.console.SendOutput(CConst.TEXT_CLIENT_EXCEPTION);
                }
            }
            CData.console.Close();
        }
    }
}
